﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

/// <summary>
/// These three classes are all concerned with reading configuration section for the wcf service section.
/// </summary>
namespace WcfHost {
    
    class WcfServiceConfigurationSection : ConfigurationSection {

        /// <summary>
        /// Gets all services specified in the configuration file.
        /// </summary>
        /// <value>The services.</value>
        [ConfigurationProperty("services", IsDefaultCollection = false)]
        [ConfigurationCollection(typeof(ServiceElementCollection))]
        public ServiceElementCollection Services {
            get {
                ServiceElementCollection servicesCollection = (ServiceElementCollection)base["services"];
                return servicesCollection;
            }
        }
    }

    /// <summary>
    /// Represents a list of service elements in a configuration file.
    /// </summary>
    public class ServiceElementCollection : ConfigurationElementCollection {

        protected override ConfigurationElement CreateNewElement() {
            return new ServiceConfigurationElement();
        }

        protected override Object GetElementKey(ConfigurationElement element) {
            return ((ServiceConfigurationElement)element).Name;
        }

    }

    /// <summary>
    /// Represents a single config element
    /// </summary>
    public class ServiceConfigurationElement : ConfigurationElement {

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
        public string Name {
            get {
                return (string)this["name"];
            }
            set {
                this["name"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the service type.
        /// </summary>
        /// <value>The type.</value>
        [ConfigurationProperty("serviceType", IsRequired = true)]
        public string ServiceType {
            get {
                return (string)this["serviceType"];
            }
            set {
                this["serviceType"] = value;
            }
        }

    }
}
